#ifndef __FIRMWARE_H_
#define __FIRMWARE_H_
#include "rclcpp/rclcpp.hpp"
#include <agv_srvs/srv/firmware_update.hpp>
#include <agv_srvs/srv/version.hpp>
#include <agv_srvs/srv/ftp_request.hpp>
#include "ftp/ftp/server.h"
namespace firmware {
class Firmware {
public:
    /**
	 * \brief Constructor
	 * \param nh - Node handle for topics.
	 */
    explicit Firmware(rclcpp::Node& nh):nh_(nh),ftp_state_(false) {};

    /// \brief Destructor
    ~Firmware() = default;

    /// \brief Initialize
    void init();
    
    /// \brief spin
    void spin();
    
    /// \brief server start
    bool start(const std::string usr, const std::string pwd, const std::string local_root);
    
    /// \brief spin stop
    // void stop() { ROS_INFO_STREAM_NAMED("firmware", "stop ftp server."); 
    //                 if (server_ != nullptr) {
    //                     server_->stop(); 
    //                     delete server_;
    //                     server_ = nullptr;
    //                 }
    //             }
protected:
    // NodeHandle 
    rclcpp::Node& nh_;
    // service to version callback
    bool versionCallback(const std::shared_ptr<agv_srvs::srv::Version::Request> req, std::shared_ptr<agv_srvs::srv::Version::Response> res);

    // service to ftp server start callback
    // bool ftpRequestCallback(agv_srvs::srv::FtpRequest::Request &req, agv_srvs::srv::FtpRequest::Response &res);

    // service to firmware update callback
    bool firmwareUpdateCallback(const std::shared_ptr<agv_srvs::srv::FirmwareUpdate::Request> req, std::shared_ptr<agv_srvs::srv::FirmwareUpdate::Response> res);

    // timer callback
    // void timerCallback(const rclcpp::TimerEvent& event);
private:
    // define service
    // ros::ServiceServer ftp_;
    rclcpp::Service<agv_srvs::srv::FirmwareUpdate>::SharedPtr update_;
    rclcpp::Service<agv_srvs::srv::Version>::SharedPtr ver_;
    // rclcpp::Timer timer_;

    // fineftp::FtpServer *server_;

    std::string fw_root_dir_;
    std::string ftp_root_dir_;
    int ftp_port_;
    //ftp retention time
    int ftp_retention_; 
    bool ftp_state_;
};
}// end namespace

#endif